package com.sgb.merchant.viewmodel;
import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.DefaultLifecycleObserver;
import androidx.lifecycle.MutableLiveData;

import com.sgb.link.entity.merchant.ApplyDetailEntity;
import com.sgb.link.entity.merchant.InvestmentDetailEntity;
import com.sgb.merchant.api.MerchantsNet;
import com.swgk.core.base.api.ICallBack;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.common.base.BaseViewModel;

import org.jetbrains.annotations.NotNull;
/**
 * @author: 王彬臣
 * @date: 2021/8/26
 * @Description: 报名详情页viewmodel
 */
public class ApplyDetailViewModel extends BaseViewModel implements DefaultLifecycleObserver {
    public MutableLiveData<InvestmentDetailEntity> ldData=new MutableLiveData<>();
    public MutableLiveData<ApplyDetailEntity> ldApply=new MutableLiveData<>();

    public ApplyDetailViewModel(@NonNull @NotNull Application application) {
        super(application);
    }

    /****
     * 获取详情
     * @param no 项目no
     */
    public void getDetails(Long no) {
        MerchantsNet.getInstance().getService().getInvestmentDetail(no).enqueue(new ICallBack<BaseEntity<InvestmentDetailEntity>>() {
            @Override
            public void onSuccess(BaseEntity<InvestmentDetailEntity> data) {
                if (data == null) {
                    return;
                }

                if (data.getData() != null) {
                    ldData.postValue(data.getData());
                }

            }

        });
    }
    public void getApplyDetail(String no){
        MerchantsNet.getInstance().getService().getApplyDetail(no).enqueue(new ICallBack<BaseEntity<ApplyDetailEntity>>() {
            @Override
            public void onSuccess(BaseEntity<ApplyDetailEntity> data) {
                if (data == null) {
                    return;
                }

                if (data.getData() != null) {
                    ldApply.postValue(data.getData());
                }
            }
        });
    }
}
